package com.beiuu.myfirstandroidapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private String[] _title = {"TabActivity","RecyclerActivity","RecyclerPullActivity","WebShowActivity","CameraActivity1","CameraActivity2","CameraActivity3","VideoActivity1",
    "BottomNavigationBarActivity"
    };

    private Class[] _activity = { TabActivity.class,RecyclerActivity.class,RecyclerPullActivity.class ,WebShowActivity.class,CameraActivity.class,CameraActivity.class,CameraActivity.class,VideoActivity.class,
    BottomNavigationBarActivity.class
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first_layout);

        Button button1 = (Button) findViewById(R.id.button_1);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this,"点击了按钮1",Toast.LENGTH_SHORT).show();

                Intent next = new Intent(MainActivity.this,RecyclerActivity.class);
                startActivity(next);
            }
        });

        //test

        ListView lv1 = (ListView) findViewById(R.id.listview_1);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,_title);
        lv1.setAdapter(adapter);
        lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(MainActivity.this,_title[position],Toast.LENGTH_SHORT).show();

                Intent next = new Intent(MainActivity.this, _activity[position]);
                if( _activity[position].equals(CameraActivity.class)){
                    next.putExtra("TAG",_title[position]);
                }
                startActivity(next);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }
}
